<*****对抗演练*****>
<template>
    <div id="expQuestion"><!---->
        <Alert type="warning" show-icon>单位的课件不允许添加个人题目</Alert>
        <Button @click="addExperimentQues" type="primary" :disabled="isDisable || status">
            <span v-if="currQuestionTotal > 0"><Icon type="ios-refresh" />更新题目</span>
            <span v-else> <Icon type="ios-add" />添加题目</span>
        </Button>
        <Button @click="delExperimentQues" type="error" icon="ios-trash-outline" style="float:right;" :disabled="isDisable || status">清空</Button>
        <Divider dashed />
        <div v-if='showDataList'>
            <QuestionList :data="currQuestionData" :showScore="false">
                <template slot="action" slot-scope="{ question, index }">
                    <Button type="error" size="small" :disabled="isDisable || status" @click="delQuestion(question,index)" style="padding:0px 3px;float:right;"><Icon type="ios-trash" /></Button>
                </template>
            </QuestionList>
            <!-- <div class="questionList" v-for="(question , index) in currQuestionData" style="font-size:13px">
                <p><span style="margin-right:0px">{{index+1}}、</span>
                    <span v-text="question.description" v-if ="question.modeCode != 4">{{question.description}}</span>
                    <span v-html="parseDescription(question)" v-if ="question.modeCode == 4">{{parseDescription(question)}}</span>
                    <Tag color="blue">{{question.modeCode | modeFilter }}</Tag>
                    <Tag color="green">{{question.difficulty | difficultyFilter}}</Tag>
                    <Tag color="geekblue">{{question.visibility | publicFilter}}</Tag>
                    <Button type="error" size="small" :disabled="isDisable || status" @click="delQuestion(question,index)" style="padding:0px 3px;float:right;"><Icon type="ios-trash" /></Button>
                </p>
                <p v-for="answer in question.answers" v-show ="question.modeCode != 4" :key="answer.answerID" style="padding-left:20px">
                    <span v-if="answer.isRight == 0" v-text="answer.description">{{answer.description}}</span>
                    <a v-if="answer.isRight == 1" v-text="answer.description">{{answer.description}}</a>
                </p>
                <p style="margin:5px 5px 5px 20px;background:#f3f6fb;padding:5px">解析：<span v-if="question.explanation" v-text="question.explanation"></span><span v-else>暂无解析</span></p>
                <Divider dashed />
            </div> -->
            <Page :total="currQuestionTotal" show-total show-elevator show-sizer
                :page-size-opts="imagePageSizeOpts" :current="queryCurrQuestionInfo.pageIndex" :page-size="10" placement="top"
                @on-change="currQuestionOnChange"
                @on-page-size-change="currQuestionChangePageSize"
                style="text-align:center;margin-top:10px;justify-content: center;"/>
        </div>
        <div style="height:calc(100% - 130px)" v-if="showDefImg">
            <no-data></no-data>
        </div>
        <Modal
            v-model="questionModal.show"
            :title="questionModal.title"
            ok-text="确定"
            cancel-text="取消"
            @on-ok="submitQuestion"
            :loading="questionModal.loading"
            :mask-closable="false"
            :width="90"
            class="question-model"
            id="questionModal">
            <Row class="question-model-row">
                <Col span="11" style="width:49%" class="question-model-col">
                    <Card dis-hover>
                        <div slot="title">
                            <p style="display: inline;">所有题目 </p>
                            <Tag color="green">{{allObjectQuestion.length}}</Tag>
                            <div style="margin-bottom:10px;float:right">
                            <Input v-model.trim="queryQuestionInfo.description"
                                    :placeholder="$t('name')" style="width: 100px;" clearable @on-change="questionOnChange(1)"/>
                            <!-- <Select filterable v-model="queryQuestionInfo.typeCode" placeholder="知识点" style="width: 170px;" multiple clearable :max-tag-count="1" @on-change="questionOnChange(1)">
                                <Option v-for="item in typeCodeObj" :key="item.dictid"  :value="item.dictid" :title="item.dictname">{{item.dictname}}</Option>
                            </Select> -->
                            <Cascader :data="treeExpClassify" v-model="queryQuestionInfo.typeCode" placeholder="知识点" @on-change="changeCascader" 
				            style="width:150px;display: inline-block;margin-left:15px" change-on-select ></Cascader>
                            <Select filterable v-model="queryQuestionInfo.difficulty" placeholder="难度" clearable style="width: 100px;" @on-change="questionOnChange(1)">
                                <Option  value="simple">简单</Option>
                                <!--<Option  value="commonly">一般</Option>-->
                                <Option  value="medium">中等</Option>
                                <Option  value="hard">较难</Option>
                            </Select>
                            <Select filterable v-model="queryQuestionInfo.modeCode" placeholder="类型" clearable style="width: 100px;" @on-change="questionOnChange(1)">
                                <Option :value="1">单选</Option>
                                <Option :value="2">多选</Option>
                                <Option :value="3">判断</Option>
                                <Option :value="4">填空</Option>
                            </Select>
                            <!--<Button @click="initQueryQuesInfo" type="error" icon="ios-trash-outline">清空过滤</Button>-->
                            </div>
                        </div>
                        <Button type="primary"  size="small" @click="selectAllQuestion">选择所有</Button>
                        <Divider dashed />
                        <div style="height: calc(100% - 120px); overflow: auto;">
                            <QuestionList 
                                :data="allQuestionData" 
                                :showChecked="true" 
                                :showScore="false"
                                :disabled="(question) => (isPublic == '1' || !isOwn) && question.visibility == 'private'"
                                @on-select="selectQuestion">
                            </QuestionList>
                            <!-- <div v-for="(question , index) in allQuestionData">
                                <p>
                                    <Checkbox label="" :disabled="(isPublic == '1' || !isOwn) && question.visibility == 'private'" @on-change="selectQuestion($event,question)" v-model="question._checked"></Checkbox>
                                    <span>{{index+1}}、</span>
                                    <span v-text="question.description" v-if ="question.modeCode != 4">{{question.description}}</span>
                                    <span v-html="parseDescription(question)" v-if ="question.modeCode == 4">{{parseDescription(question)}}</span> -->
                                    <!-- 展示方向类型 -->
                                    <!-- <Tag color="blue">{{pointFilter(question.typeCode)}}</Tag> -->
                                    <!-- <Tag color="blue" v-for="(point,index) in filterAllPoints(question.typeCode || question.type)" :key="index">{{point}}</Tag> -->
                                    <!-- <Tag color="blue">{{question.modeCode | modeFilter }}</Tag>
                                    <Tag color="green">{{question.difficulty | difficultyFilter}}</Tag>
                                    <Tag color="geekblue">{{question.visibility | publicFilter}}</Tag> -->
                                    <!--<InputNumber v-model="question.score" :max="1000" :min="1" size="small" placeholder="分值" style="width:70px" @on-change="changeScore($event,question)"/> 分-->
                                <!-- </p>
                                <p v-for="answer in question.answers" v-show ="question.modeCode != 4" :key="answer.answerID" style="padding-left:20px">
                                    <span v-if="answer.isRight == 0" v-text="answer.description">{{answer.description}}</span>
                                    <a v-if="answer.isRight == 1" v-text="answer.description" style="color:var(--status-yes)">{{answer.description}}</a>
                                </p>
                                <p style="margin:10px 0 0 20px;">解析：<span v-if="question.explanation" v-text="question.explanation"></span><span v-else>暂无解析</span></p>
                                <Divider dashed /> -->
                            <!-- </div>	 -->
                        </div>
                        <Page :total="questionTotal" show-total 
                            show-elevator
                            :page-size-opts="imagePageSizeOpts" :current="queryQuestionInfo.pageIndex" :page-size="10" placement="top"
                            @on-change="questionOnChange"
                            @on-page-size-change="questionChangePageSize" style="text-align:center;margin-top:10px;"/>
                   
                    </Card>
                </Col>
                <Col span="11" style="width:49%;margin-left:2%" class="question-model-col">
                    <Card dis-hover style="height: 100%;">
                        <div slot="title">
                            <p style="display: inline;">已选题目 </p>
                            <Tag color="green">{{selectQuestionData.length}}</Tag>
                        </div>
                        <Button type="primary"  size="small" @click="removeAllQuestion">清空所有</Button>
                        <Divider dashed />
                        <div style="height: calc(100% - 76px); overflow: auto; padding-right: 10px;">
                            <QuestionList 
                                :data="selectQuestionData"
                                :showScore="false">
                                <template slot="action" slot-scope="{ question,index }">
                                    <Button type="error" size="small" @click="removeQuestion(question,index)" style="padding:0px 3px;float:right;"><Icon type="ios-trash" /></Button>
                                </template>
                            </QuestionList>
                            <!-- <div class="questionList overflow" v-for="(question , index) in selectQuestionData" style="font-size:13px">
                                <p><span style="margin-right:0px">{{index+1}}、</span>
                                    <span v-text="question.description" v-if ="question.modeCode != 4">{{question.description}}</span>
                                    <span v-html="parseDescription(question)" v-if ="question.modeCode == 4">{{parseDescription(question)}}</span>
                                    <Tag color="blue">{{question.modeCode | modeFilter }}</Tag>
                                    <Tag color="green">{{question.difficulty | difficultyFilter}}</Tag>
                                    <Button type="error" size="small" @click="removeQuestion(question,index)" style="padding:0px 3px;float:right;"><Icon type="ios-trash" /></Button>
                                </p>
                                <p v-for="answer in question.answers" v-show ="question.modeCode != 4" :key="answer.answerID" style="padding-left:20px">
                                    <span v-if="answer.isRight == 0" v-text="answer.description">{{answer.description}}</span>
                                    <a v-if="answer.isRight == 1" v-text="answer.description" style="color:var(--status-yes)">{{answer.description}}</a>
                                </p>
                                <p style="margin:5px 5px 5px 20px;background:#f3f6fb;padding:5px">解析：<span v-if="question.explanation" v-text="question.explanation"></span><span v-else>暂无解析</span></p>
                                <Divider dashed />
                            </div> -->
                        </div>
                    </Card>
                </Col>
            </Row>
        </Modal>
    </div>
</template>

<script>
import {allDirection,experType} from '@/api/dict.js'
import {addExpQuestion,modifyExpQuestion,delExpQuestion,queryExpQuestion,delExpQuestionS} from '@/api/selfStudy/courseExp'
import { queryObjectiveList,queryObjectiveAnswerList} from '@/api/question'
import QuestionList from '@/components/question-list'
export default {
    name: 'expQuestion',
    components:{QuestionList},
    props:['ecid','status','isPublic','isOwn'],
    data(){
    return {
        isDisable:true,
        imagePageSizeOpts:[10,20],
        USER_ID:'',
        questionCol:[
//    	  {
//          type: 'selection',
//          width: 60,
//          align: 'center'
//        },
        {
            type: 'index',
            width: 60,
            align: 'center',
            ellipsis: true
        },
        {
            title: '名称',
            key: 'description',
            align: 'center',
            tooltip: true,
//	        render:(h,params) => {
//	          return h('a',{
//	            on:{
//	              'click':() => {
//	                this.preQuestionFn(params.row);
//	              }
//	            }
//	          },this.escape2Html(params.row.description))
//	        },
        },
        {
            title: '知识点',
            key: 'typeCode',
            align: 'center',
            ellipsis: true,
            render:(h,params) => {
//	          return h('span',this.$options.filters.pointFilter(params.row.typeCode,this.typeCodeObj))
                return h('Tooltip', {                
                    props: {                  
                        placement: 'top',                  
                        transfer: true,
                        maxWidth:200,
                    },
                    style: {                  
                        width:'100%'	
                    }   
                }, [
                    h('div',{
                        style: {                  
                            'overflow': 'hidden',
                            'text-overflow': 'ellipsis'		
                        }  
                    },this.$options.filters.pointFilter(params.row.typeCode,this.typeCodeObj)),
                    h('span', {                
                        slot: 'content',               
                        style: {                  
                            whiteSpace: 'normal',
                            wordBreak:'break-all'
                        }              
                    }, this.$options.filters.pointFilter(params.row.typeCode,this.typeCodeObj))              
                ])
            }
        },
        {
            title: '难度',
            key: 'difficulty',
            align: 'center',
            ellipsis: true,
            render:(h,params) => {
            return h('span',this.$options.filters.difficultyFilter(params.row.difficulty))
            }
        },
        {
            title: '类型',
            key: 'modeCode',
            align: 'center',
            ellipsis: true,
            render:(h,params) => {
            return h('span',this.$options.filters.modeFilter(params.row.modeCode))
            }
        },
        {
            title: '创建时间',
            key: 'createTime',
            align: 'center',
            ellipsis: true
        }
        ],
        questionCol1:[
        {
            type: 'selection',
            width: 60,
            align: 'center'
        },
        {
            type: 'index',
            width: 60,
            align: 'center',
            ellipsis: true
        },
        {
            title: '名称',
            key: 'description',
            align: 'center',
            tooltip: true,
//	        render:(h,params) => {
//	          return h('a',{
//	            on:{
//	              'click':() => {
//	                this.preQuestionFn(params.row);
//	              }
//	            }
//	          },this.escape2Html(params.row.description))
//	        },
        },
        {
            title: '知识点',
            key: 'typeCode',
            align: 'center',
            ellipsis: true,
            render:(h,params) => {
//	          return h('span',this.$options.filters.pointFilter(params.row.typeCode,this.typeCodeObj))
                return h('Tooltip', {                
                    props: {                  
                        placement: 'top',                  
                        transfer: true,
                        maxWidth:200,
                    },
                    style: {                  
                        width:'100%'	
                    }   
                }, [
                    h('div',{
                        style: {                  
                            'overflow': 'hidden',
                            'text-overflow': 'ellipsis'		
                        }  
                    },this.$options.filters.pointFilter(params.row.typeCode,this.typeCodeObj)),
                    h('span', {                
                        slot: 'content',               
                        style: {                  
                            whiteSpace: 'normal',
                            wordBreak:'break-all'
                        }              
                    }, this.$options.filters.pointFilter(params.row.typeCode,this.typeCodeObj))              
                ]) 
            }
        },
        {
            title: '难度',
            key: 'difficulty',
            align: 'center',
            ellipsis: true,
            render:(h,params) => {
            return h('span',this.$options.filters.difficultyFilter(params.row.difficulty))
            }
        },
        {
            title: '类型',
            key: 'modeCode',
            align: 'center',
            ellipsis: true,
            render:(h,params) => {
            return h('span',this.$options.filters.modeFilter(params.row.modeCode))
            }
        },
        {
            title: '创建时间',
            key: 'createTime',
            align: 'center',
            ellipsis: true
        }
        ],
        currQuestionData:[],
        allQuestionData:[],
        selectQuestionData:[],
        questionTotal:0,
        currQuestionTotal:0,
        queryQuestionInfo:{
            pageIndex:1,
            pageSize:10,
            typeCode:[]
        },
        queryCurrQuestionInfo:{
            pageIndex:1,
            pageSize:10,
            order:'asc',
            sortBy:'orderNo'
        },
        questionListLoading:false,
        questionModal:{
            show:false,
            title:'添加题目',
            loading:true
        },
        typeCodeObj:[],
        allObjectQuestion:[],
        showDataList:true,
        showDefImg: false,
        direct: [],
        treeExpClassify:[]
    }
    },
    watch:{

    },
    filters:{
        difficultyFilter:(val)=>{
            let difficultyStr='';
            if(val){
            val = val.toLowerCase();
            }
            switch(val){
                case 'simple':difficultyStr = '简单';break;
                case 'commonly':difficultyStr = '一般';break;
                case 'medium':difficultyStr = '中等';break;
                case 'hard':difficultyStr = '较难';break;
            }
            return difficultyStr;
        },
        modeFilter(type){
        //1--单选  2--多选 3---判断
            let status = '';
            switch(type){
            case 1:status = '单选';break;
            case 2:status = '多选';break;
            case 3:status = '判断';break;
            case 4:status = '填空';break;
            default:status = '暂无';break;
            }
            return status;
        },
        publicFilter(type){
            if(type === 'share'){
                return '单位'
            }else if(type === 'private'){
                return '个人'
            }else if(type === 'public'){
                return '系统'
            }
        },
        pointFilter(code,obj){
            if(code&&obj.length>0){
                if(code.includes(',')){
                    code = code.split(',');
                    return code.map(codes=>{
                    return obj.filter(items=>items.dictid===codes)[0].dictname
                    }).join(',')
                }else{
                    return obj.filter(item=>item.dictid===code)[0].dictname || '暂无';
                }
            }
        }
    },
    computed:{
    
    },
    mounted(){
    console.log(this.ecid);
    this.queryCurrQuestionInfo.ecid = this.ecid;
    this.getAllPointTree()
    // this.getAllPoint(); 
//    this.getExperimentQues();
    this.queryAllObjectQuestion();
    },
    beforeDestroy(){
        
    },
    methods:{
        initQueryQuesInfo(){
            this.queryQuestionInfo = {
                pageIndex:1,
                pageSize:10,
                typeCode:[]
            };
        },
        addExperimentQues(){
            this.queryQuestionInfo = {
                pageIndex:1,
                pageSize:10,
                typeCode:[]
            };
            this.queryObjectQuestionList();
            this.getAllExperimentQues();
//	    	this.selectQuestionData = JSON.parse(JSON.stringify(this.currQuestionData));
            this.questionModal.show = true;
        },
        getExperimentQues(){
            queryExpQuestion(this.queryCurrQuestionInfo).then(data=>{
            if(data.code == 1){
                let quesDetailList = data.data.items.map(ques => {
                    //获取题目详情
                    let question = this.allObjectQuestion.find(question => question.questionID == ques.questionId);
                    if(question){
                        ques.name = question.description;
                        ques.description = question.explanation;
                        // if(question.modeCode == 3){
                        //     this.$set(question,'answers',[
                        //         {
                        //             isRight:question.answers[0].isRight == 0 ? 0 :1,
                        //             answerID:'1',
                        //             description:"【A】正确"
                        //         },
                        //         {
                        //             isRight:question.answers[0].isRight == 1 ? 0 :1,
                        //             answerID:'2',
                        //             description:"【B】错误"
                        //         }
                        //     ]);
                        // }
                        //this.queryObjectiveAnswerList(question);
                        return Object.assign(question,ques);
                    }else{
                        ques.description ="该题目已被删除"
                        return ques;
                    }
                });
                this.currQuestionData = quesDetailList;
                this.currQuestionTotal = data.data.total;
                this.isDisable = false;
                if(this.currQuestionData.length > 0){
                    this.showDataList = true
                    this.showDefImg = false
                }else{
                    this.showDataList = false
                    this.showDefImg = true
                }
            }else {
                this.currQuestionData = [];
                this.$Message.error(data.message)
            }
            })
            .catch(err=>{
            console.log(err)
            })
        },
        getAllExperimentQues(){
            let params = {
                pageIndex:1,
                pageSize:999,
                ecid:this.ecid
            };
            queryExpQuestion(params).then(data=>{
            if(data.code == 1){
                let quesDetailList = data.data.items.map(ques => {
                    //获取题目详情
                    let questions = this.allObjectQuestion.filter(question => question.questionID == ques.questionId);
                    if(questions.length > 0){
                        this.queryObjectiveAnswerList(questions[0]);
                        return Object.assign(questions[0],ques);
                    }else{
                        ques.description ="该题目已被删除或查看权限不足"
                        return ques;
                    }
                });
                this.selectQuestionData = quesDetailList;
//	            this.currQuestionTotal = data.data.total;
            }else {
                this.selectQuestionData = [];
                this.$Message.error(data.message)
            }
            })
            .catch(err=>{
            console.log(err)
            })
        },
        cancleLoading(name){
            this[name].loading = false;
            setTimeout(() => {
                this[name].loading = true;
            })
        },
        submitQuestion(){
            if(this.selectQuestionData.length == 0){
                this.$Message.warning('请选择题目');
                this.cancleLoading('questionModal');
                return;
            }
            let questionList = this.selectQuestionData.map((ques,index) => {
                return {
                    "orderNo": index,
                    "questionId": ques.questionID
                }
            });
            let data = {
            "ecid": this.ecid,
            "questionList": questionList
            };
            if(this.currQuestionTotal <= 0){ //创建题目
                addExpQuestion(data).then(data=>{
                // console.log(res)
                if(data.code == 1){
                    this.$Message.info('操作成功');
                    this.questionModal.loading = false;
                    this.questionModal.show = false;
                    this.selectQuestionData = [];
                    this.getExperimentQues();
                }else {
                    this.cancleLoading('questionModal');
                    this.$Message.error(data.message);
                }
                })
                .catch(err=>{
                    this.cancleLoading('questionModal');
                    console.log(err)
                })
            }else{
                this.delExperimentQues().then(data => {
                    modifyExpQuestion(this.ecid,questionList).then(data=>{
                    // console.log(res)
                    if(data.code == 1){
                        this.$Message.info('操作成功');
                        this.questionModal.loading = false;
                        this.questionModal.show = false;
                        this.selectQuestionData = [];
                        this.getExperimentQues();
                    }else {
                        this.cancleLoading('questionModal');
                        this.$Message.error(data.message);
                    }
                    })
                    .catch(err=>{
                    this.cancleLoading('questionModal');
                    console.log(err)
                    })
                });
            }
        },
        delExperimentQues(){
            return new Promise((resolve,reject) => {
                delExpQuestion(this.ecid).then(data=>{
                // console.log(res)
                if(data.code == 1){
                    this.getExperimentQues();
                    resolve();
                }else {
                    this.$Message.error(data.message)
                }
                })
                .catch(err=>{
                console.log(err)
                })
            })
        },
        queryAllObjectQuestion(){
            let params = {
                pageIndex:1,
                pageSize:999
            }
            queryObjectiveList({},params).then(data=>{
            if(data.code===1){
                if(data.data.items && data.data.items.length>0){
                let allObjectQuestion = data.data.items;
                allObjectQuestion.forEach(question => {
                    question.questionID = question.id
                });
                this.allObjectQuestion = allObjectQuestion;
                this.getExperimentQues();
                }else{
                    this.allObjectQuestion = [];
                }
            }
            })
        },
        queryObjectQuestionList(){
    //	    let obj={
    //	      pageIndex:_this.objective.page || 1,
    //	      pageSize:_this.objective.pageSize || 20,
    //	      visibility:_this.objective.visibility||'all',
    //	    }
    //	    if(_this.objective.questionname){
    //	      obj.description = _this.objective.questionname
    //	    }
    //	    if(_this.objective.typeCode){
    //	      obj.typeCode = _this.objective.typeCode.join(',')
    //	    }
    //	    if(_this.objective.modeCode){
    //	      obj.modeCode = _this.objective.modeCode
    //	    }
    //	    if(_this.objective.difficulty){
    //	      obj.difficulty = _this.objective.difficulty
    //	    }
            let copeQueryQuestionInfo= JSON.parse(JSON.stringify(this.queryQuestionInfo));
            let {pageIndex,pageSize,...data} = copeQueryQuestionInfo;
            let params = {
                pageIndex,pageSize
            }
            // data.typeCode = data.typeCode.join(',');
            if(data.typeCode && data.typeCode.length) {
					data.typeCode = data.typeCode[data.typeCode.length - 1];
				} else {
					data.typeCode = ''
            }
                console.log('===',data);
            queryObjectiveList(data,params).then(data=>{
            if(data.code===1){
                if(data.data.items && data.data.items.length>0){
                this.allQuestionData = data.data.items;
                this.allQuestionData.forEach(ques => {
                    ques.questionID = ques.id;
                    this.$set(ques,'_checked',false);
                    if(!ques.name) {
                        this.$set(ques, 'name', ques.description);
                    }
                    let selectQuestionIds = this.selectQuestionData.map(ques => ques.questionID);
                    if(selectQuestionIds.findIndex(id => ques.questionID == id) != -1){
                        ques._checked = true;
                    }
                    if(ques.modeCode == 3){
                        this.$set(ques,'answers',[
                            {
                                isRight:ques.answers[0].isRight == 0 ? 0 :1,
                                answerID:'1',
                                description:"【A】正确"
                            },
                            {
                                isRight:ques.answers[0].isRight == 1 ? 0 :1,
                                answerID:'2',
                                description:"【B】错误"
                            }
                        ]);
                    }
                    //this.queryObjectiveAnswerList(ques);
                })
                console.log(this.allQuestionData);
                }else{
                    this.allQuestionData = [];
                }
                this.questionTotal = data.data.total;
            }
            })
        },
        getAllPoint(){
            let params = {
            dictTypeID:'directionType'
            }
            allDirection(params).then(data=>{
            if(data.code===1){
                this.typeCodeObj = data.attribute.attribute[0].dictEntryList;
                console.log('🚀 ~ file: expQuestion.vue:675 ~ allDirection ~ this.typeCodeObj:', this.typeCodeObj)
            }
            })
        },

        getAllPointTree () { //获取所有方向
            experType().then(res => {
                if (res.code == 1) {
                    let attribute = res.attribute.attribute;
                    this.direct = attribute[0].dictEntryList
                    let treeExpClassify = {};
                    attribute[0].dictEntryList.forEach(dict => {
                        if (dict.parentid) { //二级
                            if (!treeExpClassify[dict.parentid]) return;
                            treeExpClassify[dict.parentid].children.push({
                                value: dict.dictid,
                                label: dict.dictname
                            })
                        } else if (!treeExpClassify[dict.dictid] && !dict.parentid) { //一级
                            treeExpClassify[dict.dictid] = {
                                value: dict.dictid,
                                label: dict.dictname,
                                children: []
                            }
                        }
                    })
                    this.treeExpClassify = Object.values(treeExpClassify);
                    console.log('experType ~ this.treeExpClassify:', this.treeExpClassify)
                }
            })
        },

        // 获取所有方向   同this.filterAllPoints 同样，只是展示样式不一样
        pointFilter (code, obj) {
            let arr1 = this.direct
            let arr2 = code.split(',');
            let str1 = ''
            let str2 = ''
            arr1.map((items) => {
                if (items.dictid === arr2[0]) {
                    str1 = items.dictname
                }
                if (items.dictid === arr2[1] && items.parentid === arr2[0]) {
                    str2 = items.dictname
                }
            })
            return `${str1} / ${str2}`
        },

       // 获取所有方向
        filterAllPoints (val) { 
            let arr = []
            let splitVal = val.split(',');
            let typeCodeObj = this.direct || []
            splitVal.forEach(split => {
                let curCode = typeCodeObj.filter(code => code.dictid === split)[0];
                if (curCode) {
                    arr.push(curCode.dictname)
                }
            })
            if (arr.length === 0) {
                arr = ['未知类型']
            }
            return arr;
        },
        
        changeCascader (value) {
            this.queryQuestionInfo.typeCode = value
            this.queryObjectQuestionList();
        },
        questionOnChange(val){
        this.queryQuestionInfo.pageIndex = val;
        this.queryObjectQuestionList();
        },
        questionChangePageSize(val){
        this.queryQuestionInfo.pageSize = val;
        this.queryObjectQuestionList();
        },
        currQuestionOnChange(val){
        this.queryCurrQuestionInfo.pageIndex = val;
        this.getExperimentQues();
        },
        currQuestionChangePageSize(val){
        this.queryCurrQuestionInfo.pageSize = val;
        this.getExperimentQues();
        },
        selectAllQuestion(e){
            this.allQuestionData.forEach(ques => {
                if(!ques._checked){
                    if(this.isPublic == '1' && ques.visibility == 'private'){
                        return
                    }
                    this.selectQuestion(true,ques)
                }
            })
        },
        selectQuestion(status,val){
            if(this.isPublic == '1' && val.visibility == "private"){ //单位的课件不允许使用个人题目
                this.$Message.warning('单位的课件不允许选择个人资源');
                return; 
            }
            if(status){ //单个选择
                this.selectQuestionData.push(val);
                val._checked = true;
            }else{
                let index = this.selectQuestionData.findIndex(ques => ques.questionID == val.questionID)
                this.removeQuestion(val,index);
            }
//	    	else{ //全选
//	    		let questionIDs = this.selectQuestionData.map(ques => ques.questionID);
//	    		questionList.forEach(ques => {
//	    			if(!questionIDs.includes(ques.questionID)){
//	    				this.selectQuestionData.push(ques);
//	    				ques._checked = true;
//	    			}
//	    		})
//	    	}
//	    	console.log(this.selectQuestionData);
        },
        cancelSelectQuestion(questionList,val){
            if(val){//单个取消
                let index = this.selectQuestionData.findIndex(ques => ques.questionID == val.questionID);
                this.selectQuestionData.splice(index,1);
                val._checked = false;
            }else{ //全部取消
                questionList.forEach(ques => {
                    let index = this.selectQuestionData.findIndex(ques => ques.questionID == ques.questionID);
                    if(index != -1){
                        ques._checked = false;
                        this.selectQuestionData.splice(index,1);
                    }
                })
            }
            console.log(this.selectQuestionData);
        },
        handleClose(e,currQuesId){
            //软件列表中的索引
            const index = this.allQuestionData.findIndex(function(value, index, arr) {
            return value.questionID == currQuesId;
            });
            if(index != -1){ 
                this.$refs.questionTb.toggleSelect(index)
            }
        },
        queryObjectiveAnswerList(question){
            queryObjectiveAnswerList(question.questionID).then(data => {
                if(data.code == 1){
                    let answ = this.sortQuestionAnswer(data.data.answers)
                    this.$set(question,'answers',answ);
                    if(question.modeCode == 3){
                        this.$set(question,'answers',[
                            {
                                isRight:question.answers[0].isRight == 0 ? 0 :1,
                                answerID:'1',
                                description:"【A】正确"
                            },
                            {
                                isRight:question.answers[0].isRight == 1 ? 0 :1,
                                answerID:'2',
                                description:"【B】错误"
                            }
                        ]);
                    }
                }
            })
        },
        //对题目答案进行排序
        sortQuestionAnswer(answer){
        if(!answer){
            return;
        }else if(answer.length>0&&answer[0].no){
            answer.sort(function(a,b){
            return parseInt(a.no)-parseInt(b.no);
            })
        }
        return answer;
        },
        removeAllQuestion(){
            this.selectQuestionData = [];
            this.allQuestionData.forEach(ques => {
                ques._checked = false;
            })
        },
        removeQuestion(ques,index){ //删除已选题目
            this.selectQuestionData.splice(index,1);
            let question = this.allQuestionData.filter(question => question.questionID == ques.questionID);
            if(question.length > 0){
            this.$set(question[0],'_checked',false);
            }
        },
        delQuestion(ques,index){
            delExpQuestionS(this.ecid,ques.questionID).then(data => {
                if(data.code == 1){
                    this.$Message.info('操作成功');
                    this.getExperimentQues();
                }else{
                    this.$Message.warning(data.message)
                }
            }).catch(error => {
                this.$Message.error(error)
            })
        },
        parseDescription(question){
            if(!question.answers){
                return;
            }
            let description;
            description = question.description.replace(/\{\{.*?\}\}/g,`<span class='quesBlank' disabled style='width:40px;padding:0px 5px;outline:none;box-shadow:none;border:none;border-bottom:1px solid rgb(168,166,200);color:#2d8cf0'></span>`);
            let el = document.createElement("div");
            el.innerHTML = description;
            let answersEle = el.getElementsByClassName('quesBlank');
            let answers = question.answers || question.keAnswerTOS;
            Array.from(answersEle).forEach((ele,index) => {
                answersEle[index].innerHTML = answers[index].explanation;
            });
            return el.innerHTML;
        },
    },
    destroyed() {
    
    }
}
</script>
<style scoped>
#expQuestion{
    height:100%;
}
#questionModal /deep/ .ivu-card-body{
    width:100%;
    max-height:80vh;
    overflow: hidden auto;
}
.question-model /deep/ .ivu-modal {
        height: calc(100% - 200px);
        min-height: 500px;
    }
    .question-model /deep/ .ivu-modal .ivu-modal-content {
        height: 100%;
    }
    .question-model /deep/ .ivu-modal .ivu-modal-content .ivu-modal-body{
        height: calc(100% - 112px);
        padding-bottom: 20px;
    }
    .question-model-row, .question-model-col,
    .question-model-row, .question-model-col /deep/ .ivu-card {
        height: 100%;
    }
    .overflow {
        overflow: auto;
    }
    #questionModal {
        /* height: 100%; */
    }
    #questionModal /deep/ .ivu-card-body{
        height: calc(100% - 50px);
        overflow: auto;
    }
    #questionModal /deep/ .ivu-card-body{
        height: calc(100% - 50px);
        overflow: auto;
    }
</style>
